package com.zs.chat.service.impl;

import com.zs.chat.entity.ChatUsersEntity;
import com.zs.chat.repository.ChatUsersDao;
import com.zs.chat.service.ChatUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author madison
 * @description
 * @date 2020/10/12 10:29 下午
 */
@Slf4j
@Service
public class ChatUserServiceImpl implements ChatUserService {

    @Autowired
    private ChatUsersDao chatUsersDao;

    @Override
    public void findAll() {
        Pageable pageRequest = PageRequest.of(0, 3, Sort.Direction.DESC, "createTime");
        List<ChatUsersEntity> all = chatUsersDao.selectUsers(pageRequest);
        all.forEach(item -> log.info("name:{},createTime:{}", item.getName(), item.getCreateTime()));
    }

    @Override
    public void findNameTest() {
        List<ChatUsersEntity> all = chatUsersDao.findByName("madison");
        all.forEach(item -> log.info("id:{}", item.getId()));
    }

    @Override
    public void insertUser() {
        ChatUsersEntity usersEntity = new ChatUsersEntity();
        usersEntity.setName("hhhhh");
        ChatUsersEntity save = chatUsersDao.save(usersEntity);
        log.info("id:{},createTime:{}",save.getId(),save.getCreateTime());
    }
}
